/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cassys.ejbs;

import cassys.application.services.UserRoleManager;
import javax.ejb.Stateless;
import cassys.data.DAOFactory;
import cassys.data.UserRoleMappingDAO;
import cassys.domain.user.User;
import cassys.domain.user.UserRoleMapping;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Resource;
import javax.ejb.SessionContext;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.ejb.TransactionManagement;
import javax.ejb.TransactionManagementType;

/**
 *
 * @author UserRoleMapping
 */
@Stateless(mappedName = "LoginController")
@TransactionManagement(TransactionManagementType.CONTAINER)
public class LoginManagerBean implements UserRoleManager {

    @Resource
    private SessionContext context;
    DAOFactory daoFactory = DAOFactory.instance(DAOFactory.HIBERNATE);

 
    @Override
    @TransactionAttribute(TransactionAttributeType.REQUIRED)
    public  List<UserRoleMapping> validateUser(String userId,String password) throws Exception{
        System.out.println("validating user");
        List<UserRoleMapping> userRoleList =null ;
        UserRoleMappingDAO loginRepository = daoFactory.getLoginDAO();
        System.out.println("rollback set2 - " + context.getRollbackOnly());
       
        try {
           List<UserRoleMapping> userMappings = loginRepository.getUser(userId,password);
            System.out.println("got the user mappings " + userMappings.size());
            return userMappings;

        } catch (Exception e) {
            System.out.println("err" + e.getMessage());
            System.out.println("err" + e.getStackTrace());
            throw e;
        }
       // System.out.println("created");
        //return userRoleList;
    }
}
